Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.DirectoryServices
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Transactions

Public Class UploadFileDAO

    Public Sub InsertData(ByVal TheClass As String, ByVal TheType As String, ByVal FileName As String, ByVal FileShortName As String, _
                            ByVal FileType As String, ByVal FileSavePath As String, ByVal FileSaveName As String, _
                            ByVal FileDesc As String, ByVal CreateBy As String, ByVal CreateAt As String)

        Dim dat As New clsData
        Dim sqlstr As New MyStringBuilder

        sqlstr.AppendFormat(" Insert into UploadFiles ")
        sqlstr.AppendFormat(" values( ")
        sqlstr.AppendFormat(" '{0}' ,", TheClass)
        sqlstr.AppendFormat(" '{0}' ,", TheType)
        sqlstr.AppendFormat(" '{0}' ,", FileName)
        sqlstr.AppendFormat(" '{0}' ,", FileShortName)
        sqlstr.AppendFormat(" '{0}' ,", FileType)
        sqlstr.AppendFormat(" '{0}' ,", FileSavePath)
        sqlstr.AppendFormat(" '{0}' ,", FileSaveName)
        sqlstr.AppendFormat(" '{0}' ,", FileDesc)
        sqlstr.AppendFormat(" '{0}' ,", CreateBy)
        sqlstr.AppendFormat(" getDate() ) ", CreateAt)

        dat.AccData(sqlstr)

    End Sub

    Public Function GetFileSaveName() As String

        Dim dat As New clsData
        Dim sqlstr As New MyStringBuilder
        Dim dt As DataTable


        sqlstr.AppendFormat("select newid()")
        dt = dat.GetData(sqlstr)

        Return dt.Rows(0)(0).ToString()

    End Function

    Public Function GetFilePath(ByVal FileGroupID As String) As String
        Dim dat As New clsData
        Dim sqlstr As New MyStringBuilder
        Dim dt As DataTable

        sqlstr.AppendFormat(" select FilePath from [FileGroup] ")
        sqlstr.AppendFormat(" where FileGroupID = '{0}' ", FileGroupID)

        dt = dat.GetData(sqlstr)

        Return dt.Rows(0)(0).ToString()

    End Function

    Public Function GetFileData(ByVal FileGroupID As String) As DataTable

        Dim dat As New clsData
        Dim sqlstr As New MyStringBuilder
        Dim dt As DataTable

        sqlstr.AppendFormat(" select b.Description,a.fileshortName,a.fileSavePath,a.fileSaveName ")
        sqlstr.AppendFormat(" from uploadfiles a inner join filegroup b ")
        sqlstr.AppendFormat(" on a.theClass = b.FileGroupID ")
        sqlstr.AppendFormat(" where b.FileGroupID = '{0}' ", FileGroupID)

        dt = dat.GetData(sqlstr)

        Return dt

    End Function
End Class
